# Contributor: Olivier Mauras <olivier@mauras.ch>
# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=borgbackup
_pkgname=borg
pkgver=1.2.1
pkgrel=0
pkgdesc="Deduplicating backup program"
url="https://www.borgbackup.org/"
arch="all"
license="BSD-3-Clause"
depends="python3 py3-packaging py3-pyzmq py3-msgpack"
makedepends="python3-dev lz4-dev acl-dev attr-dev openssl1.1-compat-dev linux-headers
	py3-setuptools py3-setuptools_scm zstd-dev"
checkdepends="py3-pytest py3-pytest-benchmark py3-dateutil"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/borgbackup/borg/releases/download/$pkgver/borgbackup-$pkgver.tar.gz"

export BORG_OPENSSL_PREFIX="/usr/include/openssl"

build() {
	# https://github.com/borgbackup/borg/issues/4891#issuecomment-615838317
	CFLAGS="$CFLAGS -DXXH_FORCE_MEMORY_ACCESS=1" \
	python3 setup.py build
}

check() {
	PYTHONPATH="$(echo "$builddir"/build/lib.linux-*)" pytest -v \
	--benchmark-skip --pyargs borg.testsuite
}

package() {
	python3 setup.py install --prefix=/usr --root="$pkgdir"

	install -Dm644 -t "$pkgdir"/usr/share/man/man1 docs/man/*.1

	install -Dm644 scripts/shell_completions/bash/$_pkgname \
		"$pkgdir"/usr/share/bash-completion/completions/$_pkgname

	install -Dm644 scripts/shell_completions/fish/$_pkgname.fish \
		"$pkgdir"/usr/share/fish/completions/$_pkgname.fish

	install -Dm644 scripts/shell_completions/zsh/_$_pkgname \
		"$pkgdir"/usr/share/zsh/site-functions/_$_pkgname

	# clean some useless files
	cd "$pkgdir"/usr/lib/python*/site-packages/borg
	find . -name '*.h' -delete -o -name '*.c' -delete -o -name '*.pyx' -delete
}

sha512sums="
47e95960c9ce7715897834f400ee1a3dcbbbd9aa1e4b69dc93618ade24caf6c046b844c9f3edd10e090795d06bed0136fbd42d6e679f0639f221b83d82545d43  borgbackup-1.2.1.tar.gz
"
